<?php

namespace Echecs\pageBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class PageController extends Controller
{
    
       public static function getNavSidebar($controller)
    {
         $navP = $controller->getDoctrine()->getRepository('EchecspageBundle:Pages:PagesRepository')->findPagesOrdered();
         $navC = $controller->getDoctrine()->getRepository('EchecspageBundle:Categorie:CategorieRepository')->findAllNavigation();    
         $categs = $controller->getDoctrine()->getRepository('EchecspageBundle:Categorie:CategorieRepository')->findAllSidebar();
         
         $tabConf[0] = $navP;
         $tabConf[1] = $navC;
         $tabConf[2] = $categs;
         return $tabConf;
    }
    
    
    public function indexAction($name)
    {
        $mapage = $this->getDoctrine()->getRepository('EchecspageBundle:Pages:PagesRepository')->findOneByNomPage($name);
        $tabconf = $this->getNavSidebar($this);         
        
        if( $name=='Accueil')
        {
            $articles = $this->getDoctrine()->getRepository('EchecspageBundle:Article:ArticlesRepository')->findAll();
             return $this->render('EchecspageBundle:Articles:indexAll.html.twig',array('articles'=>$articles, 'categories'=> $tabconf[2], 'navigationP' => $tabconf[0], 'navigationC' => $tabconf[1], 'categorie'=>$name));
        }
    else 
        {
             return $this->render('EchecspageBundle:Pages:index.html.twig',array('page' => $mapage, 'categories'=> $tabconf[2], 'navigationP' => $tabconf[0], 'navigationC' => $tabconf[1]));
        }
       
    }
}
